package com.itheima_06;

import java.util.Arrays;
import java.util.Scanner;

public class SelcetArry {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入你要查找的数：");
        int i1 = sc.nextInt();
        int arr[]={25,123,44,2,1,6,4,84,64,152};
        Arrays.sort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
        System.out.println();
         int index= Select(arr,i1);
        System.out.println(index);
    }

    private static int Select(int[] arr, int i1) {
        int min=0;
        int max=arr.length-1;
        while (min<=max){
            int mid=(max+min)/2;
            if(arr[mid]>i1){
                max=mid-1;
            }else if(arr[mid]<i1){
                min=mid+1;
                }else{
                return mid;
            }

            }

        return -1;
    }
}
